package com.tj.collection.db.dao.impl;

import com.fqgj.common.base.AbstractBaseMapper;
import com.tj.collection.db.dao.ClCommentDao;
import com.tj.collection.db.entity.ClCommentEntity;
import org.springframework.stereotype.Repository;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * Created with IntelliJ IDEA.
 * User: sm
 * Date: 2019-09-03
 * Time: 10:22
 */
@Repository
public class ClCommentDaoImpl extends AbstractBaseMapper<ClCommentEntity> implements ClCommentDao {

    @Override
    public List<ClCommentEntity> selectCommentListByParams(Map<String, Object> params) {
        if (!params.containsKey("deleted")) {
            params.put("deleted", 0);
        }
        return getSqlSession().selectList(this.getStatement("selectByParams"), params);
    }

    @Override
    public List<ClCommentEntity> selectCommonByCollectionNo(String collectionNo) {
        Map<String, Object> params = new HashMap<>();
        params.put("collectionNo", collectionNo);
        return this.selectCommentListByParams(params);
    }

    @Override
    public List<ClCommentEntity> getLatestListByAllocationNos(List<String> allocationNos) {
        Map<String, Object> map = new HashMap<>();
        map.put("allocationNos", allocationNos);
        return getSqlSession().selectList(this.getStatement("getLatestListByAllocationNos"), map);
    }

    /**
     * 查询不同手机号的最后一条记录
     *
     * @param collectionNo
     * @return
     */
    @Override
    public List<ClCommentEntity> selectLatestCommonByCollectionNo(String collectionNo) {
        Map<String, Object> params = new HashMap<>();
        params.put("collectionNo", collectionNo);
        return getSqlSession().selectList(this.getStatement("selectLatestCommonByCollectionNo"), params);
    }

    @Override
    public Integer selectTodayCommonByCollectionNo(String collectionNo,int type) {
        Map<String, Object> map = new HashMap<>();
        map.put("collectionNo", collectionNo);
        map.put("type", type);
        return getSqlSession().selectOne(this.getStatement("selectTodayCommonByCollectionNo"), map);
    }
}
